<?php

class tutorialController extends appRain_Base_Core
{
	public $name ="Tutorial";
	
	/**
     * Execute before the action
     */
	public function __preDispatch()
	{
		$this->set("section_title","Tutorial");
        $this->set("selected","tutorial");
	}
	
	/* This is the starting page of Tutorial */
	public function indexAction($action=null, $id=null,$page = 1)
    {
        // Fetch a page from Page Manager and
        // set Meta information.
        $tutpage = $this->staticPageNameToMetaInfo('tutorial');

        if($action == 'bytut')
        {
            // Attach few Addons
            $this->addons = Array('defaultvalues','validation','ajaxsubmit');

            // Fetch a Single Tutorial from Information Set
            // by Tutorial Id
            $tut = App::InformationSet()->findById($id);
            $this->set('tut',$tut);

            // Overwrite the page title
            $this->page_title = $tut['title'];
        }
        else if($action == 'bycat')
        {
            /**
             * See how we can optimize the pagination
             * You can make it more easier as per need
             */
            $tutentry = App::InformationSet('tut-entry')
                        ->setPagination('Yes')
                        ->setSmartPaging(true)
                        ->setPage($page)
                        ->setLimit(2)
                        ->setHLink(App::Helper('Config')->baseurl("/tut-by-cat/{$id}/[page]/" . App::Helper('Utility')->Text2Normalize(App::CategorySet()->idToName($id))))
                        ->setNextCaption('Next >>')
                        ->setPrevCaption('<< Prev')
                        ->findAll(
                                    "1 ORDER BY id DESC",
                                    Array(
                                            Array("category"=>$id),
                                            "AND",
                                            Array("status"=>"Public")
                                          )
                                 );
            $this->set('tutentry',$tutentry);

            // Overwrite the page title
            $this->page_title = App::CategorySet()->idToName($id);

        }
        else
        {
            /**
             * See how we can optimize the pagination
             * You can make it more easier as per need
             */
            $page = is_numeric($action) ? $action : 1;
            $tutentry = App::InformationSet('tut-entry')
                        ->setPagination('Yes')
                        ->setSmartPaging(true)
                        ->setPage($page)
                        ->setHLink(App::Helper('Config')->baseurl("/tutorial"))
                        ->setLimit(2)
                        ->setNextCaption('Next >>')
                        ->setPrevCaption('<< Prev')
                        ->findAll("1 ORDER BY id DESC",Array(Array("status"=>"Public")));
            $this->set('tutentry',$tutentry);
        }

        // Add another add-on with
        // previouse collection
        $this->addons[] = 'dropdownmenu';

        // Assign Common values
        // in template
        $this->set("action",$action);
		$this->set("tutpage",$tutpage);
        $this->set("catid",(($action == 'bycat')?$id:""));
    }
	
	public function manageAction($action=NULL,$id=NULL)
    {
        $this->setAdminTab('tut');
		
	}
}

?>